package com.obviousframework.mom.model;

import java.io.Serializable;
import java.util.Collection;
import java.util.Collections;
import java.util.LinkedHashMap;

public class Message implements Serializable {

	private static final long serialVersionUID = -191667616832471571L;

	private String id;

	private Serializable body;

	private final LinkedHashMap<String, Tag> tags = new LinkedHashMap<String, Tag>();

	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}

	@SuppressWarnings("unchecked")
	public <S extends Serializable> S getBody() {
		return (S) body;
	}

	public void setBody(Serializable body) {
		this.body = body;
	}

	public void addTag(String key) {
		addTag(key, null);
	}

	public void addTag(String key, String value) {
		tags.put(key, new Tag(key, value));
	}

	public void removeTag(String key) {
		tags.remove(key);
	}

	public void clearTag() {
		tags.clear();
	}

	public Collection<Tag> getTags() {
		return Collections.unmodifiableCollection(tags.values());
	}
}
